package com.kuaixueit.crm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.kuaixueit.crm.common.ResultVO;
import com.kuaixueit.crm.pojo.CDept;
import com.kuaixueit.crm.service.DeptService;

@Controller
@RequestMapping("dept")
public class DeptController {
  
  //注入业务层的deptServiceImpl
  @Autowired
  private DeptService deptService;
  
  @RequestMapping("getDept")
  @ResponseBody
  public CDept getDeptById(Integer id){
    return deptService.getDeptById(id);
  }

  /**
   * 返回值 会被转化为json 包含total，rows
   */
  @RequestMapping("list")
  @ResponseBody
  public ResultVO list(@RequestParam(defaultValue="1")Integer page,@RequestParam(defaultValue="10")Integer rows){
    PageInfo pageList = new PageInfo<>();
    try {
      pageList = deptService.getPageList(page, rows);
    } catch (Exception e) {
      e.printStackTrace();
      //出现异常就可以发送一个邮件或者短信给运维。
      return new ResultVO(null,null,false,"服务器内部错误，请联系管理员");
    }
    return new ResultVO(pageList.getTotal(), pageList.getList(), true, "查询成功");
  }
}
